<?php

namespace App\Transformers;

use App\Models\Filiale;
use League\Fractal\TransformerAbstract;

class FilialeTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['company', 'prizeRecords'];

    public function transform(Filiale $filiale)
    {
        return [
            'id' => $filiale->id,
            'name' => $filiale->name,
            'phone' => $filiale->phone,
            'address' => $filiale->address,
            'longitude' => $filiale->longitude,
            'latitude' => $filiale->latitude,
            'forbidden' => (bool)$filiale->forbidden,
            'created_at' => $filiale->created_at->toDateTimeString(),
            'updated_at' => $filiale->updated_at->toDateTimeString(),
        ];
    }

    public function includeCompany(Filiale $filiale)
    {
        return $this->item($filiale->company, new CompanyTransformer());
    }

    public function includePrizeRecords(Filiale $filiale)
    {
        $prizeRecords = $filiale->prizeRecords;

        return $this->collection($prizeRecords, new PrizeRecordTransformer());
    }
}